package com.ecarx.library_base.usb;

import android.os.StatFs;
import android.text.TextUtils;

public class UDiskDevice {

    /**
     * fsLabel = M-OM-5M-MM-3UM-EM-L
     * path = /storage/CC93-996E
     * internalPath = /mnt/media_rw/CC93-996E
     * statFs = android.os.StatFs@3e0dd36
     * avaibleSize = 737501184
     * totalSize = 14004781056
     */
    /**
     * U盘名称
     */
    private final String fsLabel;
    /**
     * U盘路径，APP访问
     */
    private String path;
    /**
     * U盘路径，Shell访问
     */
    private String internalPath;
    private StatFs statFs;
    private long avaibleSize;
    private long totalSize;
    private String uuid;

    public UDiskDevice(String fsLabel) {
        this.fsLabel = fsLabel;
    }

    public UDiskDevice(String fsLabel, String path, String internalPath, StatFs statFs, long avaibleSize, long totalSize, String uuid) {
        this.fsLabel = fsLabel;
        this.path = path;
        this.internalPath = internalPath;
        this.statFs = statFs;
        this.avaibleSize = avaibleSize;
        this.totalSize = totalSize;
        this.uuid = uuid;
    }

    public String getFsLabel() {
        return fsLabel;
    }

    public String getUSBName() {
        if(TextUtils.isEmpty(fsLabel)){
            return uuid;
        }
        return fsLabel;
    }

    public String getPath() {
        return path;
    }

    public String getInternalPath() {
        return internalPath;
    }

    public StatFs getStatFs() {
        return statFs;
    }

    public long getAvaibleSize() {
        return avaibleSize;
    }

    public long getTotalSize() {
        return totalSize;
    }

    public String getUuid() {
        return uuid;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        UDiskDevice that = (UDiskDevice) o;

        if (fsLabel != null ? !fsLabel.equals(that.fsLabel) : that.fsLabel != null) return false;
        if (path != null ? !path.equals(that.path) : that.path != null) return false;
        return internalPath != null ? internalPath.equals(that.internalPath) : that.internalPath == null;
    }

    @Override
    public int hashCode() {
        int result = fsLabel != null ? fsLabel.hashCode() : 0;
        result = 31 * result + (path != null ? path.hashCode() : 0);
        result = 31 * result + (internalPath != null ? internalPath.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "UsbDevice{" +
                "fsLabel='" + fsLabel + '\'' +
                ", path='" + path + '\'' +
                ", internalPath='" + internalPath + '\'' +
                ", statFs=" + statFs +
                ", avaibleSize=" + avaibleSize +
                ", totalSize=" + totalSize +
                ", uuid=" + uuid +
                '}';
    }
}
